package com.itheima.tlias.mapper;

import com.itheima.tlias.dto.SelectDeptDTO;
import com.itheima.tlias.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *部门mapper
 */
@Mapper
public interface DeptMapper {

    @Select("select id,name,update_time from dept order by update_time desc")
    List<SelectDeptDTO> selectAll();

    @Insert("insert into dept(name,update_time,create_time) values (#{d.name},#{d.updateTime},#{d.createTime})" )
    int insertDept(@Param("d")Dept dept);

    @Delete("delete from dept where id = #{id}")
    int deleteById(@Param("id")Integer id);

    @Select("select id,name from dept where id = #{id}")
    SelectDeptDTO selectById(@Param("id")Integer id);

    @Update("update dept set name = #{d.name},update_time = #{d.updateTime} where id = #{d.id}")
    int updateById(@Param("d")Dept dept);

    @Select("select id,name from dept where name = #{name}")
    Dept selectDeptByName(@Param("name")String name);

    int batchDelete(@Param("ids") List<Integer> id);
}
